package org.example.route.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.route.model.dto.PriceQueryDTO;
import org.example.route.model.pojo.StationRoute;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface StationRouteMapper {
    @Insert("insert into station_route (station_id, route_id, sequence, arrival_time, go_time, train_id,status) VALUES " +
            "(#{stationId},#{routeId},#{sequence},#{arrivalTime},#{goTime},#{trainId},#{status})")
    void add(StationRoute stationRoute);

    List<StationRoute> list(Long routeId, Long stationId, Long trainId);

    List<StationRoute> getStartByPriceDTO(PriceQueryDTO priceQueryDTO);

    List<StationRoute> getTargetByPriceDTO(PriceQueryDTO priceQueryDTO);

    @Select("select station_id from station_route where id = #{goId1}")
    Long getStationIdById(Long goId1);

    @Select("select train_id from station_route where id = #{goId1}")
    Long getTrainIdById(Long goId1);

    @Select("select arrival_time from station_route where id = #{goId2}")
    LocalDateTime getEndTimeById(Long goId2);

    @Select("select arrival_time from station_route where id = #{goId1}")
    LocalDateTime getStartTimeById(Long goId1);

    @Select("select * from station_route where status = #{statusNormal} and go_time < #{now}")
    List<StationRoute> listOutDateStationRoute(Long statusNormal, LocalDateTime now);

    @Select("select * from station_route where station_id = #{id}")
    List<StationRoute> listByStationId(Long id);



    @Select("select * from station_route where train_id = #{trainId}")
    List<StationRoute> getByTrainId(Long trainId);

    //根据路线id查询站点节点
    @Select("select * from station_route where route_id = #{routeId}")
    List<StationRoute> getByRouteId(Long routeId);

    @Delete("delete from station_route where route_id = #{routeId}")
    void deleteAllByRouteId(Long routeId);
}
